package cn.topevery.garden.dal.dao.impl;

import cn.topevery.garden.dal.dao.GpsPosTraceDao;
import cn.topevery.garden.entity.po.GpsPosTrace;
import cn.topevery.garden.entity.query.GpsPosTraceQuery;
import cn.topevery.garden.entity.vo.GpsPosTraceVO;
import cn.topevery.garden.framework.base.BaseDaoImpl;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.db.entity.SqlQueryMate;
import hw.topevery.framework.db.enums.ScriptConditionEnum;
import hw.topevery.framework.entity.DbCsp;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * GPS详情
 *
 * @author code-generate
 * @date 2021-09-13
 */
@Repository
public class GpsPosTraceDaoImpl extends BaseDaoImpl<GpsPosTrace> implements GpsPosTraceDao {
    @Override
    public <P extends DbCsp> List<GpsPosTrace> getSearch(P para) {
        return null;
    }

    

    @Override
    public DataPager<GpsPosTraceVO> listPage(String name, GpsPosTraceQuery query) {
        String table = "v_gps_pos_trace_curr tgpt";

        String columns = "tgpt.*,tgpt.c_long as c_lng,'" + name + "' as c_name";
        int pageIndex = query.pageIndex - 1;
        int pageSize = query.pageSize;

        SqlQueryMate sqlQueryMate = new SqlQueryMate(table).setColumns(columns).setOrderBy("tgpt.c_id desc");
        sqlQueryMate
//                .where(true, "tgpt.c_db_status", ScriptConditionEnum.Eq, 0)
                .where(query.getId() != null, "tgpt.c_obj_id", ScriptConditionEnum.Eq, query.getId())
                .where(query.getObjType() != null, "tgpt.c_obj_type", ScriptConditionEnum.Eq, query.getObjType())
                .where(StringUtils.isNotBlank(query.beginDate), "tgpt.c_db_create_date", ScriptConditionEnum.GreaterThanEq, query.beginDate)
                .where(StringUtils.isNotBlank(query.endDate), "tgpt.c_db_create_date", ScriptConditionEnum.LessThanEq, query.endDate);

        return getDataPager(sqlQueryMate, pageSize, pageIndex, GpsPosTraceVO.class);
    }
}
